loadMenu();

function loadMenu(){
    ajax("/find_all_menu",{},function(datas){
        showMenu(datas);
    })
}

function showMenu(datas){
    var menustr = "";
    var currentURL = document.URL;
    var start = currentURL.lastIndexOf("/");
    var end = currentURL.indexOf("?");
    var url = currentURL.substring(start+1,end);
    var urlIndex = -1;
    for(var i=0;i<datas.length;i++){
        var d = datas[i];
        if(d.url==url){
            urlIndex = i;
        }
        menustr +=
            " <li>\n" +
            "<a href=\""+d.url+"?token="
            +localStorage.token+"\">"+d.menu_name
            +"</a></li>\n" ;
    }
    nav.innerHTML = (
        "                <div class=\"item\">\n" +
        "                    <h3>总部管理</h3>\n" +
        "                    <ul>\n" +
        menustr+
        "                    </ul>\n" +
        "                </div>\n" +
        "\n"
    );
    setColor(urlIndex);
}




function setColor(i){
    var lis = document.getElementsByTagName("li");
    lis[i].style.background = "white";
    lis[i].getElementsByTagName("a")[0].style.color = "#2e2f81";
}